package com.ktg.web.wms;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ktg.ktgcommon.aop.SecuredOperation;
import com.ktg.ktgcommon.domain.wms.WmWarehouse;
import com.ktg.ktgcommon.result.R;
import com.ktg.service.WasService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
public class WmsController {
    @Resource
    private WasService wasService;
    @PostMapping("/api/was/list")
    @SecuredOperation("wm:use:list")
    public R pageInfo(@RequestParam(defaultValue = "1") Integer pageNo,
                      @RequestParam(defaultValue = "10") Integer pageSize, @RequestBody WmWarehouse wmWarehouse){
        Page<WmWarehouse> wmWarehousePage = new Page<>(pageNo, pageSize);
        Page<WmWarehouse> wmWarehousePage1 = wasService.getUserByPage(wmWarehousePage,wmWarehouse);
        if (wmWarehousePage1 != null) {
            return R.OK(wmWarehousePage1);
        }
        return R.FAIL();
    }
    @PostMapping ("/api/was/edit")
    @SecuredOperation("wm:use:edit")
    public R edist(WmWarehouse wmWarehouse){
        if(wmWarehouse.getWarehouseId()==null){
            int i = wasService.addWas(wmWarehouse);
            return i>0 ?R.OK() :R.FAIL();
        }
        int i = wasService.editWas(wmWarehouse);
        return i>0 ?R.OK() :R.FAIL();
    }
    @PostMapping ("/api/was/editList/{wareHouseId}")
    public R editList(@PathVariable("wareHouseId")Integer wareHouseId) {
        return R.OK(wasService.selectById(wareHouseId));
    }

}
